fix: multi-table DELETE+LIMIT syntax error and inaccurate index comment in cleanup_orphan_stats - #115
Merged
Conversation
Co-authored-by: XuPeng-SH <39627130+XuPeng-SH@users.noreply.github.com> Agent-Logs-Url: https://github.com/matrixorigin/Memoria/sessions/67302052-8c88-4cd1-8252-1b108337af6b
Copilot
AI
changed the title
[WIP] Discuss database operations and potential performance issues
perf(storage): add missing indexes and cap unbounded DB operations
Mar 24, 2026
…leanup_orphan_stats Co-authored-by: XuPeng-SH <39627130+XuPeng-SH@users.noreply.github.com> Agent-Logs-Url: https://github.com/matrixorigin/Memoria/sessions/8109f997-3693-4df7-9c8e-3484b74b92d4
Copilot
AI
changed the title
perf(storage): add missing indexes and cap unbounded DB operations
perf(storage): add missing indexes, cap unbounded ops, fix multi-table DELETE+LIMIT bug
Mar 24, 2026
Copilot
AI
changed the title
perf(storage): add missing indexes, cap unbounded ops, fix multi-table DELETE+LIMIT bug
fix: multi-table DELETE+LIMIT syntax error and inaccurate index comment in cleanup_orphan_stats
Mar 24, 2026
XuPeng-SH
marked this pull request as ready for review
March 24, 2026 15:59
XuPeng-SH
approved these changes
Mar 24, 2026
XuPeng-SH
enabled auto-merge (squash)
March 24, 2026 15:59
XuPeng-SH
disabled auto-merge
March 24, 2026 16:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two issues in the batched
cleanup_orphan_statsrewrite and one misleading comment introduced by the previous perf commit.Bug fix: multi-table DELETE with LIMIT is invalid MySQL/MatrixOne syntax
DELETE alias FROM t1 LEFT JOIN t2 … LIMIT nis rejected at runtime — MySQL forbidsORDER BY/LIMITon multi-table deletes. Every other batchedDELETEin the file is single-table for exactly this reason.Replaced with the standard two-step pattern used elsewhere:
mem_memories_statshasmemory_idas itsPRIMARY KEY(one row per memory), so the SELECT never returns duplicates and the loop terminates correctly.Comment fix:
idx_memories_user_observedscopeThe original comment claimed the index also accelerates
archive_stale_working. It doesn't — that function usesTIMESTAMPDIFF(HOUR, observed_at, NOW()) > ?, which wrapsobserved_atin a function and prevents a B-tree range scan. The index only helpshealth_capacity()'s direct range predicateobserved_at >= NOW() - INTERVAL 30 DAY. Comment corrected accordingly.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.